//
//  LSTestSelectCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/7/26.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSTestSelectCell.h"
#import "LSTestSelectModel.h"

@interface LSTestSelectCell ()
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIButton *selectButton;
@end

@implementation LSTestSelectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        [self.contentView addSubview:self.arrowImageView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.selectButton];
    }
    return self;
}

- (void)setModel:(LSTestSelectModel *)model {
    _model = model;
    self.nameLabel.text = model.name;
    WS
//    [self.arrowImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(weakSelf.nameLabel.mas_left).with.offset(TitleRect.size.width-8-15);
//        make.centerY.equalTo(weakSelf.contentView.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(22, 22));
//    }];
//    [self.selectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(weakSelf.nameLabel.mas_left).with.offset(TitleRectWithWords.size.width+8);
//        make.centerY.equalTo(weakSelf.contentView.mas_centerY).with.offset(4);
//        make.size.mas_equalTo(CGSizeMake(44, 30));
//    }];
    if (model.isOpen) {
        self.arrowImageView.transform = CGAffineTransformIdentity;
    } else {
        self.arrowImageView.transform = CGAffineTransformMakeRotation(-(M_PI / 2));
    }
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xiala"]];
    }
    return _arrowImageView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, (ScreenWidth-50-16), 44) andText:@"" andTextColor:hexColor(333333) andFont:[UIFont systemFontOfSize:17] andTextAlignment:NSTextAlignmentLeft];
    }
    return _nameLabel;
}

- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [[UIButton alloc] init];
        _selectButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_selectButton setImage:[UIImage imageNamed:@"yuanquan"]  forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"yuanquan_selected"] forState:UIControlStateSelected];
        [_selectButton addTarget:self action:@selector(selectButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectButton;
}

- (void)selectButtonClick {
    if ([self.delegate respondsToSelector:@selector(didSelectTestSelectCellWithModel:)]) {
        [self.delegate didSelectTestSelectCellWithModel:_model];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
